<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增文章')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-article-add">
        <input name="uid" class="form-control" type="hidden" th:value="${user.userId}"/>
        <input name="areaId" class="form-control" type="hidden" th:value="${user.dept.deptId}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label">栏目分类：</label>
            <div class="col-sm-8">
                <select name="category" class="form-control m-b">
                    <option selected="selected" th:value="${menu.menuId}" th:text="${menu.menuName}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">标题：</label>
            <div class="col-sm-8">
                <input name="title" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">简介：</label>
            <div class="col-sm-8">
                <textarea name="brief" class="form-control"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">发布时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input id="defaultDate" name="publishTime" class="form-control" placeholder="yyyy-MM-dd"
                           type="text">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">文章类型：</label>
            <div class="col-sm-8">
                <select id="type" name="tpe" class="form-control m-b">
                    <option selected="selected">请选择</option>
                    <option value="1">文章</option>
                    <option value="2">图文</option>
                    <option value="3">图集</option>
                    <option value="4">视频</option>
                    <option value="5">直播</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">封面：</label>
            <div class="col-sm-8">
                <div class="file-loading">
                    <input id="filePath" class="file" type="file" multiple data-min-file-count="1" data-theme="fas">
                </div>
            </div>
        </div>
       <!-- <div id="photos" class="form-group" style="display: none">
            <label class="col-sm-3 control-label">图集内容：</label>
            <div class="col-sm-8">
                <div class="file-loading">
                    <input id="multiFile" type="file" class="file" multiple>
                </div>
            </div>
        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">内容：</label>
            <div class="col-sm-8">
                <div class="ibox-content no-padding">
                    <textarea name="photos" class="summernote">
                    </textarea>
                </div>
            </div>
        </div>
        <div id="video" class="form-group" style="display: none">
            <label class="col-sm-3 control-label">视频地址：</label>
            <div class="col-sm-8">
                <input name="videoId" class="form-control" type="hidden">
                <input name="videoPath" class="form-control" placeholder="请选择视频地址"></input>
            </div>
        </div>
        <div id="live" class="form-group" style="display: none">
            <label class="col-sm-3 control-label">直播地址：</label>
            <div class="col-sm-8">
                <input name="videoId" class="form-control" type="hidden">
                <input name="videoPath" class="form-control" placeholder="请选择直播流地址"></input>
            </div>
        </div>
        <!--
        <div class="form-group">
            <label class="col-sm-3 control-label">视频ID：</label>
            <div class="col-sm-8">
                <input name="videoId" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">外链：</label>
            <div class="col-sm-8">
                <input name="url" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">作者：</label>
            <div class="col-sm-8">
                <input name="author" class="form-control" type="text">
            </div>
        </div>-->
        <!-- <div class="form-group">
             <label class="col-sm-3 control-label">区域ID：</label>
             <div class="col-sm-8">
                 <input name="areaId" class="form-control" type="text">
             </div>
         </div>
         <div class="form-group">
             <label class="col-sm-3 control-label">添加时间：</label>
             <div class="col-sm-8">
                 <div class="input-group date">
                     <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                     <input name="addTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                 </div>
             </div>
         </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">点击量：</label>
            <div class="col-sm-8">
                <input name="clickCount" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否显示：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('sys_show_hide')}">
                    <input type="radio" th:id="${'isShow_' + dict.dictCode}" name="isShow" th:value="${dict.dictValue}"
                           th:checked="${dict.default}">
                    <label th:for="${'isShow_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <!-- <div class="form-group">
             <label class="col-sm-3 control-label">TV是否显示：</label>
             <div class="col-sm-8">
                 <div class="radio-box" th:each="dict : ${@dict.getType('sys_show_hide')}">
                     <input type="radio" th:id="${'isTvShow_' + dict.dictCode}" name="isTvShow" th:value="${dict.dictValue}" th:checked="${dict.default}">
                     <label th:for="${'isTvShow_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                 </div>
             </div>
         </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">微信是否显示：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('sys_show_hide')}">
                    <input type="radio" th:id="${'isWxShow_' + dict.dictCode}" name="isWxShow"
                           th:value="${dict.dictValue}" th:checked="${dict.default}">
                    <label th:for="${'isWxShow_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">PC是否显示：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('sys_show_hide')}">
                    <input type="radio" th:id="${'isPcShow_' + dict.dictCode}" name="isPcShow"
                           th:value="${dict.dictValue}" th:checked="${dict.default}">
                    <label th:for="${'isPcShow_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <!--  <div class="form-group">
              <label class="col-sm-3 control-label">首页是否显示：</label>
              <div class="col-sm-8">
                  <div class="radio-box" th:each="dict : ${@dict.getType('sys_show_hide')}">
                      <input type="radio" th:id="${'isShowIndex_' + dict.dictCode}" name="isShowIndex" th:value="${dict.dictValue}" th:checked="${dict.default}">
                      <label th:for="${'isShowIndex_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                  </div>
              </div>
          </div>
          <div class="form-group">
              <label class="col-sm-3 control-label">是否公开：</label>
              <div class="col-sm-8">
                  <div class="radio-box" th:each="dict : ${@dict.getType('sys_show_hide')}">
                      <input type="radio" th:id="${'isPublish_' + dict.dictCode}" name="isPublish" th:value="${dict.dictValue}" th:checked="${dict.default}">
                      <label th:for="${'isPublish_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                  </div>
              </div>
          </div>-->
        <!-- <div class="form-group">
             <label class="col-sm-3 control-label">是否初审核通过，1通过，0未审，2不通过：</label>
             <div class="col-sm-8">
                 <div class="radio-box" th:each="dict : ${@dict.getType('sys_show_hide')}">
                     <input type="radio" th:id="${'isCheck_' + dict.dictCode}" name="isCheck" th:value="${dict.dictValue}" th:checked="${dict.default}">
                     <label th:for="${'isCheck_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                 </div>
             </div>
         </div>
         <div class="form-group">
             <label class="col-sm-3 control-label">未通过原因：</label>
             <div class="col-sm-8">
                 <textarea name="checkCase" class="form-control"></textarea>
             </div>
         </div>
         <div class="form-group">
             <label class="col-sm-3 control-label">审核时间：</label>
             <div class="col-sm-8">
                 <div class="input-group date">
                     <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                     <input name="checkTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                 </div>
             </div>
         </div>
         <div class="form-group">
             <label class="col-sm-3 control-label">审核人ID：</label>
             <div class="col-sm-8">
                 <input name="checkUser" class="form-control" type="text">
             </div>
         </div>
         <div class="form-group">
             <label class="col-sm-3 control-label">是否终审，0未审核，1终审通过，2，终审不通过：</label>
             <div class="col-sm-8">
                 <div class="radio-box" th:each="dict : ${@dict.getType('sys_job_status')}">
                     <input type="radio" th:id="${'isFinalCheck_' + dict.dictCode}" name="isFinalCheck" th:value="${dict.dictValue}" th:checked="${dict.default}">
                     <label th:for="${'isFinalCheck_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                 </div>
             </div>
         </div>
         <div class="form-group">
             <label class="col-sm-3 control-label">终审不通过原因：</label>
             <div class="col-sm-8">
                 <textarea name="finalCheckCase" class="form-control"></textarea>
             </div>
         </div>
         <div class="form-group">
             <label class="col-sm-3 control-label">终审时间：</label>
             <div class="col-sm-8">
                 <div class="input-group date">
                     <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                     <input name="finalCheckTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                 </div>
             </div>
         </div>
         <div class="form-group">
             <label class="col-sm-3 control-label">终审员ID：</label>
             <div class="col-sm-8">
                 <input name="finalCheckUser" class="form-control" type="text">
             </div>
         </div>
         <div class="form-group">
             <label class="col-sm-3 control-label">添加人员ID：</label>
             <div class="col-sm-8">
                 <input name="adminId" class="form-control" type="text">
             </div>
         </div>-->
        <!--  <div class="form-group">
              <label class="col-sm-3 control-label">点赞数：</label>
              <div class="col-sm-8">
                  <input name="likes" class="form-control" type="text">
              </div>
          </div>
          <div class="form-group">
              <label class="col-sm-3 control-label">是否删除：</label>
              <div class="col-sm-8">
                  <div class="radio-box" th:each="dict : ${@dict.getType('sys_show_hide')}">
                      <input type="radio" th:id="${'isDel_' + dict.dictCode}" name="isDel" th:value="${dict.dictValue}" th:checked="${dict.default}">
                      <label th:for="${'isDel_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                  </div>
              </div>
          </div>
          <div class="form-group">
              <label class="col-sm-3 control-label">文章模型：</label>
              <div class="col-sm-8">
                  <input name="articleModel" class="form-control" type="text">
              </div>
          </div>
          <div class="form-group">
              <label class="col-sm-3 control-label">用户ID：</label>
              <div class="col-sm-8">
                  <input name="uid" class="form-control" type="text">
              </div>
          </div>-->
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: summernote-js" />
<script type="text/javascript">
    $(function () {
        $("#multiFile").fileinput({
            'theme': 'explorer-fas',
            'uploadUrl': '#',
            overwriteInitial: false,
            initialPreviewAsData: true
        });
        $('.summernote').summernote({
            lang: 'zh-CN'
        });
        var now = new Date();
        //格式化日，如果小于9，前面补0
        var day = ("0" + now.getDate()).slice(-2);
        //格式化月，如果小于9，前面补0
        var month = ("0" + (now.getMonth() + 1)).slice(-2);
        //拼装完整日期格式
        var today = now.getFullYear() + "-" + (month) + "-" + (day);
        $("#defaultDate").val(today);

        $("#type").change(function () {
            if ($(this).val() == 1||2||3) {
/*
                $("#photos").hide();
*/
                $("#video").hide();
                $("#live").hide();
            } /*else if ($(this).val() == 2) {
                $("#photos").show();
                $("#video").hide();
                $("#live").hide();
            } else if ($(this).val() == 3) {
                $("#photos").show();
                $("#video").hide();
                $("#live").hide();
            }*/ else if ($(this).val() == 4) {
                $("#photos").hide();
                $("#video").show();
                $("#live").hide();
            } else if ($(this).val() == 5) {
                $("#photos").hide();
                $("#video").hide();
                $("#live").show();
            }
        })
    });

    var prefix = ctx + "article/article"
    $("#form-article-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        /*$.operate.save(prefix + "/add", $('#form-article-add').serialize());*/
        //文件上传
        var form = $("#form-article-add")[0];
        var formData = new FormData(form);
        /*formData.append('file', files[0]);*/
        if ($('#filePath')[0].files[0] == null) {
            $.modal.alertWarning("请先选择文件路径");
            return false;
        }
        formData.append('file', $('#filePath')[0].files[0]);
      /*  var files = $('#multiFile')[0].files;
        if (files.length > 0) {
            for (var i = 0; i < files.length; i++) {
                formData.append('multiFile', files[i]);
            }
        }*/
        /* var url = prefix + "/add";
         var data = {"formData": formData};
         $.operate.submit(url, "post", "json", data);*/
        $.ajax({
            url: prefix + "/add",
            type: 'post',
            cache: false,
            data: formData,
            processData: false,
            contentType: false,
            dataType: "json",
            success: function (result) {
                console.log(result)
                setTimeout(function () {
                    $.modal.close();
                }, 300);
                var parent = window.parent;
                parent.$.modal.msgSuccess("操作成功!");
                parent.$.table.refresh();
            }
        });
    };

    $("input[name='addTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='checkTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='finalCheckTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='publishTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
</script>
</body>
</html>